<?php include _include(ADMIN_PATH.'view/htm/header.inc.htm');?>

<!--{hook admin_user_list_start.htm}-->

<div class="row">
	<div class="col-xs-12">
		<div class="btn-group m-b-1" role="group">
			<?php echo admin_tab_active($menu['user']['tab'], 'list');?>
		</div>
	</div>
</div>

<div class="row">
	<div class="col-md-2 m-b-sm">
		<select id="srchtype" value="<?php echo $srchtype; ?>" class="form-control">
			<option value=""><?php echo lang('search_type');?></option>
			<option value="uid"><?php echo lang('uid');?>：</option>
			<option value="username" selected><?php echo lang('username');?>：</option>
			<option value="email"><?php echo lang('email');?>：</option>
			<option value="gid"><?php echo lang('user_group');?>：</option>
			<option value="create_ip"><?php echo lang('create_ip');?>：</option>
		</select>
	</div>
	<div class="col-md-3 m-b-sm">
		<input type="text" id="keyword" placeholder="<?php echo lang('keyword');?>" value="<?php echo $keyword; ?>"  class="form-control" />
	</div>
	<div class="col-md-2 m-b-sm">
		<button id="search" class="form-control btn btn-primary"><?php echo lang('search');?></button>
	</div>
</div>

<div class="row">
	<div class="col-lg-12">
		<div class="card">
			<div class="table-responsive">
				<table class="table" style="min-width: 800px">
					<thead>
						<tr>
							<th width="60" class="text-center"><?php echo lang('delete');?></th>
							<th width="50">ID：</th>
							<!--<th>手机号</th>-->
							<th width="150"><?php echo lang('email');?></th>
							<th width="150"><?php echo lang('username');?></th>
							<th width="100"><?php echo lang('user_group');?></th>
							<th width="100"><?php echo lang('create_date');?></th>
							<th width="100"><?php echo lang('create_ip');?></th>
							<th width="60"><?php echo lang('operation');?></th>
						</tr>
					</thead>
					<tbody id="userlist">
				<?php foreach($userlist as &$_user){ ?>
					<tr uid="<?php echo $_user['uid']; ?>">
						<td class="text-center"><input type="checkbox" name="delete" /></td>
						<td><?php echo $_user['uid']; ?></td>
						<!--<td><?php echo $_user['mobile']; ?></td>-->
						<td><?php echo $_user['email']; ?></td>
						<td><?php echo $_user['username']; ?></td>
						<td><?php echo $_user['groupname']; ?></td>
						<td><?php echo $_user['create_date_fmt']; ?></td>
						<td><?php echo $_user['create_ip_fmt']; ?></td>
						<td><a href="<?php echo url("user-update-$_user[uid]"); ?>"><?php echo lang('edit');?></a></td>
					</tr>
				<?php } ?>
					</tbody>
				</table>
			</div>
			<hr class="m-t-0" />
			<p><button class="btn btn-sm m-l-1" id="confirm"><?php echo lang('delete');?></button></p>
		</div>
		<nav class="text-center"><ul class="pagination"><?php echo $pagination; ?></ul></nav>
	</div>
</div>

<!--{hook admin_user_list_end.htm}-->

<?php include _include(ADMIN_PATH.'view/htm/footer.inc.htm');?>

<script>
var jbody = $("#userbody");
var jcreate = $('#create');
var jconfirm = $("#confirm");
var jsearch = $("#search");
var jsrchtype = $("#srchtype");
var jkeyword = $('#keyword');
var juserlist = $('#userlist');

jsrchtype.val(jsrchtype.attr('value'));

jcreate.on('click', function(event) {
	window.location = xn.url('user-create');
});

jsearch.on('click', function(){
	var srchtype = jsrchtype.val();
	srchtype = srchtype ? srchtype : 'uid';
	var keyword = $("#keyword").val();
	var url = xn.url('user-list-'+srchtype+'-'+xn.urlencode(keyword)+'-1');
	window.location = url;
});
jkeyword.on('keydown', function(e) {
	if(e.keyCode == 13) jsearch.trigger('click');
});

// 删除选中的用户
jconfirm.on('click', function(){
	var jchecked = juserlist.find('input[name="delete"]').filter(function(){ return this.checked; });
	if(jchecked.length < 1) return alert("<?php echo lang('please_check_delete_user');?>");
	if(!window.confirm("<?php echo lang('user_delete_confirm');?>")) return false;
	jchecked.each(function() {
		jtr = $(this).parents('tr');
		var uid = jtr.attr('uid');
		if(uid == 1) return alert('<?php echo lang('user_admin_cant_be_deleted');?>');
		$.xpost(xn.url('user-delete'), {uid:uid}, function(code, message) {
			if(code != 0) return $.alert(message);
			jtr.remove();
		});
	});
});


$('#nav_pc li.user, #nav_mobile li.user').tab('show');

</script>

<!--{hook admin_user_list_js.htm}-->
